﻿Imports Oracle.DataAccess.Client
Public Class fListaMoviDetalle
    Private lBodegaDe As String = ""
    Private lProducto As String = ""
    Private lImei As String = ""
    Private lIccid As String = ""

    Public Property pBodegaDe()
        Get
            Return lBodegaDe
        End Get
        Set(ByVal value)
            lBodegaDe = value
        End Set
    End Property

    Public Property pProducto()
        Get
            Return lProducto
        End Get
        Set(ByVal value)
            lProducto = value
        End Set
    End Property
    Public ReadOnly Property pImei()
        Get
            Return lImei
        End Get
    End Property
    Public ReadOnly Property pIccid()
        Get
            Return lIccid
        End Get
    End Property

    Private Sub fListaMoviDetalle_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = conn.CreateCommand
        Try
            Dim entro As Integer = 0
            Dim pSelect As String = "SELECT IDBODEGA,IDPRODUCTO,CONSECUTIVO,IMEI,ICCID,FECHAINGRESO "
            Dim pFrom As String = " FROM INV_DETALLEINVENTARIOS "
            Dim pWhere As String = " WHERE "
            Dim pOrder As String = " ORDER BY CONSECUTIVO,FECHAINGRESO"
            If pBodegaDe.ToString.Length > 0 Then
                pWhere = pWhere & " IDBODEGA=:PBODEGA "
                cmd.Parameters.Add("PBODEGA", OracleDbType.Varchar2).Value = pBodegaDe
                entro = 1
            End If
            If pProducto.ToString.Length > 0 Then
                If entro = 1 Then
                    pWhere &= " AND "
                End If
                pWhere &= " IDPRODUCTO=:PIDPRODUCTO "
                cmd.Parameters.Add("PIDPRODUCTO", OracleDbType.Varchar2).Value = pProducto
            End If
            cmd.CommandText = pSelect & pFrom & pWhere
            conn.Open()
            Dim dt As New Data.DataTable
            dt.Load(cmd.ExecuteReader)
            INV_DETALLEINVENTARIOSDataGridView.DataSource = dt
            INV_DETALLEINVENTARIOSDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub AsignaEquipo(ByVal Fila As Integer)
        If Fila >= 0 Then
            'MessageBox.Show("hola")
            lImei = INV_DETALLEINVENTARIOSDataGridView.Rows(Fila).Cells("IMEI").Value
            lIccid = INV_DETALLEINVENTARIOSDataGridView.Rows(Fila).Cells("ICCID").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub


    Private Sub INV_DETALLEINVENTARIOSDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles INV_DETALLEINVENTARIOSDataGridView.CellMouseDoubleClick
        AsignaEquipo(e.RowIndex)
    End Sub

    Private Sub INV_DETALLEINVENTARIOSDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles INV_DETALLEINVENTARIOSDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaEquipo(INV_DETALLEINVENTARIOSDataGridView.CurrentRow.Index)
        End If
    End Sub
End Class